package com.example.zg3_park.news

import androidx.lifecycle.viewModelScope
import androidx.paging.*
import com.example.lib_base.entity.NewsEntity
import com.example.lib_base.entity.NewsEntityItem
import com.example.lib_base.mvvm.BaseViewModel
import com.example.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class NewsViewModel @Inject constructor(val apiService: ApiService):BaseViewModel() {

    fun getNews():Flow<PagingData<NewsEntityItem>> {
        return Pager(config = PagingConfig(pageSize = 10), pagingSourceFactory = {
            NewsDataSource(apiService)
        }).flow.cachedIn(viewModelScope)
    }
}